package com.zj.leetcode.medium.dynamicProgramming;

/**
 * @program: algorithm
 * @description:
 * 跳跃游戏
 * 55 jump-game
 * @author: Zhang Bo
 * @create: 2022-01-14 17:05
 **/
public class JumpGame{
    public static void main(String[] args) {
        Solution solution = new JumpGame().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean canJump(int[] nums) {
            int len = nums.length;
            int maxPos = 0;
            for (int i = 0; i < len && i <= maxPos; i++) {
                int curMax = i + nums[i];
                maxPos = Math.max(maxPos, curMax);
                if (maxPos >= len - 1) {
                    return true;
                }
            }
            return false;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}